function gadget:GetInfo()
	return {
		name 		= "Houndmaster",
		desc 		= "Gives wolves to Houndmaster",
		author 		= "CarRepairer",
		date 		= "2009-11-16",
		license   	= "GNU GPL, v2 or later",
		layer 		= 1,
		enabled 	= true,
	}
end


if (gadgetHandler:IsSyncedCode()) then
--SYNCED

local spGetUnitPosition     = Spring.GetUnitPosition
local spGetUnitVelocity     = Spring.GetUnitVelocity
local spGetUnitSeparation   = Spring.GetUnitSeparation

local echo   = Spring.Echo

local HOUNDTIMER = 20

local hunter_defid = UnitDefNames['hunter'].id
local wolf_defid = UnitDefNames['wolf'].id

local hunter_hounds = {}
local hunter_houndcount = {}
local hounds = {}

local addwolves = {}

local function AddHound(hunterID, team)
	local x,y,z = Spring.GetUnitPosition(hunterID)
	x = x + 20
	z = z + 20
	y = Spring.GetGroundHeight(x,z)
	local newWolfID = Spring.CreateUnit(wolf_defid, x,y,z, 0, team)
	SendToUnsynced('NoSelect', newWolfID)
	Spring.GiveOrderToUnit(newWolfID, CMD.GUARD, {hunterID}, {})
	hounds[newWolfID] = hunterID
	hunter_hounds[hunterID][newWolfID] = true
	hunter_houndcount[hunterID] = hunter_houndcount[hunterID] + 1
end

function gadget:UnitDestroyed(u, udid, team)
	local master_ID = hounds[u]
	if master_ID then
		hunter_hounds[master_ID][u] = nil
		hunter_houndcount[master_ID] = hunter_houndcount[master_ID] - 1
	elseif hunter_houndcount[u] then
		for wolfID, _ in pairs(hunter_hounds[u]) do
			Spring.TransferUnit(wolfID, Spring.GetGaiaTeamID())
		end
		for houndID,_ in pairs(hunter_hounds[u]) do
			hounds[houndID] = nil
		end
		hunter_hounds[u] = nil
		hunter_houndcount[u] = nil
	end
end

function gadget:UnitCreated(u, udid, team)
	if udid == hunter_defid then
		hunter_hounds[u] = {}
		hunter_houndcount[u] = 0
		
		addwolves[u] = team
	end
end

--[[ This might not be a good idea
function gadget:AllowCommand(unitID, unitDefID, teamID,cmdID, cmdParams, cmdOptions)
	local hound_master = hounds[unitID]
	if hound_master then
		if cmdID ~= CMD.GUARD or #cmdParams ~= 1 or cmdParams[1] ~= hound_master then
			return false
		end
	end
	return true
end
--]]

function gadget:GameFrame(f)

	for hunterID, team in pairs(addwolves) do
		AddHound(hunterID, team)
		addwolves[hunterID] = nil
	end

	if f % (32 * HOUNDTIMER) < 0.1 then
		for hunterID, houndcount in pairs(hunter_houndcount) do
			if houndcount < 3 then
				AddHound(hunterID, Spring.GetUnitTeam(hunterID))
			end
		end
	end
end



------ SYNCED ----------
else
------ UNSYNCED --------

local spSetUnitNoSelect     = Spring.SetUnitNoSelect

local function NoSelect(cmd, unitID)	
	if (type(unitID) ~= 'number') then
		return
	end
	spSetUnitNoSelect(unitID, true)
end

function gadget:Initialize()
  gadgetHandler:AddSyncAction('NoSelect', NoSelect)
end

function gadget:Shutdown(unitID)
  gadgetHandler:RemoveSyncAction('NoSelect') 
end

------ UNSYNCED ----------
end










